import socket
import sys


def socketHandle():
    serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    host = socket.gethostname()
    port = 9999
    serverSocket.bind((host, port))
    serverSocket.listen(5)
    while True:
        clinetSockert, addr = serverSocket.accept()
        print("连接地址: %s" % str(addr))
        msg = clinetSockert.recv(1024)
        print(msg.decode('utf-8'))
        msg = '欢迎使用python socket 编程\n'
        clinetSockert.send(msg.encode('utf-8'))
        clinetSockert.close()


if __name__ == '__main__':
    socketHandle()
